package com.sxfq.loansupermarket.backsystem.modular.weixin.config;


import java.io.File;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ObjectMetadata;

public class OssUtil2 {
    //以下几个参数值必填，参考文章最后文档
    static String endpoint = "http://oss-cn-qingdao.aliyuncs.com";
    static String accessKeyId = "oss获取";
    static String accessKeySecert = "oss获取";
    static String bucketName = "yueang2";

    /**
     * 上传单个文件到OSS
     * @param file 要上传的文件File对象
     * @param objName 上传后的文件名，包含文件夹，比如 game/game/test.txt
     * @return
     */
    public static boolean uploadFileToOss(File file, String objName) {
        try {
            OSSClient ossClient = null;
            try {
                ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecert);
            }catch (Exception e){
                e.printStackTrace();
            }
            ObjectMetadata meta = new ObjectMetadata();
            ossClient.putObject(bucketName, objName, file, meta);
            ossClient.shutdown();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}